#ifndef ESPEAK_H
#define ESPEAK_H
extern "C" {
#include <speak_lib.h>

#ifdef __WIN32__
#include <windows.h>
#define sleep(x) Sleep(1000*x)
#endif
}
#include <iostream>
#include <string>
typedef int (callback_type)(short *wav, int num, espeak_EVENT *pEv);
class Espeak
{
public:
    Espeak(const char *esp_data_path);
    virtual ~Espeak();
    int set_speak_file(const std::string& filename);

    int set_rate(int rate);
    int update_valume(int val);
    int set_format(int format);

    int set_gender(unsigned char gender);
    int set_age(unsigned char age);
    int set_variant(unsigned char var);
    int set_language(const std::string& language);
    int set_voice_name(const std::string& voicename);
    int set_voice(const std::string& voice);

    int set_speak_text(const std::string& text);
    int set_voice_by_properties();
    int set_voice_by_properties(const std::string& voice_name, const std::string& language,
                             unsigned char gender, unsigned char age, unsigned char variant);
    int set_output_method(espeak_AUDIO_OUTPUT output);
    int reset();
    int save_to_file(const std::string &text, callback_type *func);
    int speak_text(const std::string& text, callback_type *func);
    int speak_file(void (*func)(void *argc), void *argc);
    size_t set_speak_text_size(size_t size);
    const espeak_VOICE **get_voice_spec_list();
private:
    static int default_speak_callback(short *wav, int num, espeak_EVENT *pEv);
private:
    std::string play_file_name;

    static std::string save_file_name;
    int save_file_flag;
    std::string to_speak_text;
    const char *pPause_speak_position;
    int pause_flag;

    std::string voice_name;
    std::string voice_language;
    unsigned char gender_, age_, variant_;
    int set_voice_ret;

    int rate_value;
    int valume_value;
    int pitch_value;
    int range_value;
    int workgap_value;
    int set_para_ret;

    espeak_AUDIO_OUTPUT init_output;
    int init_buf_lenght;
    char *pInit_path;
    int init_options;
    int init_ret;
    const char *pEspeak_data_path;
    espeak_VOICE voice_spec;
    const espeak_VOICE **ppVoice_spec_list;
    size_t sp_text_size;

};

#endif // ESPEAK_H
